/*
 * Created on Apr 27, 2006
 *
 * Copyright (c) Patrick Armstrong 2002-2007. All Rights Reserved
 */
package org.dime.mine.bot;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import org.dime.mine.game.Board;

/**
 * Guess is a solution algorithm. It simply opens a location at random.
 * 
 * @author Owner
 */
public class Guess extends AbstractStrategy
{
    // TODO improve Guess
    private Random r = new Random();

    public boolean execute(Board board)
    {
        List<Board.Location> l = new LinkedList<Board.Location>();

        for (int i = 0; i < board.getRows(); i++)
        {
            for (int j = 0; j < board.getColumns(); j++)
            {
                if (board.check(i, j) == Board.NOT_OPEN)
                {
                    l.add(board.getLocation(i, j));
                }
            }
        }

        if (l.size() > 0)
        {
            int index = r.nextInt(l.size());
            l.get(index).open();
            return true;
        }
        return false;
    }
}